package com.sxt.business.controller;


import java.util.Date;

import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sxt.business.domain.Inport;
import com.sxt.business.service.IInportService;
import com.sxt.business.vo.InportVO;
import com.sxt.system.domain.User;
import com.sxt.system.utils.DataGridView;
import com.sxt.system.utils.ResultObj;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 俊哥
 * @since 2019-11-15
 */
@RestController
@RequestMapping("inport")
public class InportController {

	@Autowired
	private IInportService inportService;
	
	private Log log = LogFactory.getLog(InportController.class);
	
	/**
	 * 查询
	 */
	@RequestMapping("loadAllInport")
	public DataGridView loadAllInport(InportVO inportVO) {
		return this.inportService.queryAllInport(inportVO);
	}
	
	/**
	 * 添加
	 */
	@RequestMapping("addInport")
	public Object addInport(Inport inport,HttpSession session) {
		try {
			//获取user
			User user = (User) session.getAttribute("user");
			inport.setOperateperson(user.getName());
			inport.setInporttime(new Date());
			this.inportService.addInport(inport);
			return ResultObj.ADD_SUCCESS;
		} catch (Exception e) {
			log.error("添加错误");
			return ResultObj.ADD_ERROR;
		}
	}
	
	/**
	 * 	修改
	 */
	@RequestMapping("updateInport")
	public ResultObj updateInport(Inport inport) {
		try {
			this.inportService.updateInport(inport);
			return ResultObj.UPDATE_SUCCESS;
		} catch (Exception e) {
			log.error("修改失败");
			return ResultObj.UPDATE_ERROR;
		}
	}
	
	/**
	 * 	删除
	 */
	@RequestMapping("deleteInport")
	public ResultObj deleteInport(Integer id) {
		try {
			inportService.removeById(id);
			return ResultObj.DELETE_SUCCESS;
		} catch (Exception e) {
			log.error("删除失败");
			return ResultObj.DELETE_ERROR;
		}
	}
	
}

